#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
  int singleNumber(vector<int> &nums) {
    std::sort(nums.begin(), nums.end());
    int i = 0;
    for (; i + 3 <= nums.size() - 1;) {
      if ((nums[i] == nums[i + 1]) && (nums[i + 1] == nums[i + 2])) {
        i += 3;
      } else {
        if (nums[i] != nums[i + 1]) {
          return nums[i];
        } else {
          return nums[i + 2];
        }
      }
    }
    return nums[nums.size() - 1];
  }
};
